package com.dianping.cat.home.jar.transform;

import com.dianping.cat.home.jar.entity.Domain;
import com.dianping.cat.home.jar.entity.Jar;
import com.dianping.cat.home.jar.entity.JarReport;
import com.dianping.cat.home.jar.entity.Machine;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;




public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Domain buildDomain(Attributes attributes) {
    String id = attributes.getValue("id");
/*  21 */     return new Domain(id);
  }




  public Jar buildJar(Attributes attributes) {
/*  28 */     String id = attributes.getValue("id");
    String version = attributes.getValue("version");
/*  30 */     Jar jar = new Jar();

    if (id != null) {
/*  33 */       jar.setId(id);
    }

    if (version != null) {
/*  37 */       jar.setVersion(version);
    }

/*  40 */     return jar;
  }


  public JarReport buildJarReport(Attributes attributes) {
/*  45 */     String domain = attributes.getValue("domain");
/*  46 */     String startTime = attributes.getValue("startTime");
/*  47 */     String endTime = attributes.getValue("endTime");
/*  48 */     JarReport jarReport = new JarReport();

/*  50 */     if (domain != null) {
/*  51 */       jarReport.setDomain(domain);
    }

/*  54 */     if (startTime != null) {
/*  55 */       jarReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/*  58 */     if (endTime != null) {
/*  59 */       jarReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/*  62 */     return jarReport;
  }


  public Machine buildMachine(Attributes attributes) {
/*  67 */     String id = attributes.getValue("id");
/*  68 */     return new Machine(id);
  }




  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/*  75 */     if (value == null || value.length() == 0) {
/*  76 */       return defaultValue;
    }

/*  79 */     if (type == Boolean.class || type == boolean.class)
/*  80 */       return (T)Boolean.valueOf(value); 
/*  81 */     if (type == Integer.class || type == int.class)
/*  82 */       return (T)Integer.valueOf(value); 
/*  83 */     if (type == Long.class || type == long.class)
/*  84 */       return (T)Long.valueOf(value); 
/*  85 */     if (type == Short.class || type == short.class)
/*  86 */       return (T)Short.valueOf(value); 
/*  87 */     if (type == Float.class || type == float.class)
/*  88 */       return (T)Float.valueOf(value); 
/*  89 */     if (type == Double.class || type == double.class)
/*  90 */       return (T)Double.valueOf(value); 
/*  91 */     if (type == Byte.class || type == byte.class)
/*  92 */       return (T)Byte.valueOf(value); 
/*  93 */     if (type == Character.class || type == char.class) {
/*  94 */       return (T)Character.valueOf(value.charAt(0));
    }
/*  96 */     return (T)value;
  }


  protected Date toDate(String str, String format, Date defaultValue) {
/* 101 */     if (str == null || str.length() == 0) {
/* 102 */       return defaultValue;
    }

    try {
/* 106 */       return (new SimpleDateFormat(format)).parse(str);
/* 107 */     } catch (ParseException e) {
/* 108 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/jar/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */